From 0a8c9d341a8cd8823188994176550edb0e8ea21f Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 16 Apr 2004 14:17:38 +0000 Subject: [PATCH] Fixed saroute for .anr files containing stops and vias; one of the 'unknown records' was actually a count of route segments. Thanks to FizzyMagic for reporting and debugging this. --- saroute.c | 110 +++++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/saroute.c b/saroute.c index d5cdfdbd6..9cd2cb849 100644 --- a/saroute.c +++ b/saroute.c @@ -81,6 +81,7 @@ my_read(void) unsigned short version; unsigned long count; + unsigned long outercount; unsigned long recsize; unsigned short stringlen; unsigned char *record; @@ -167,64 +168,73 @@ my_read(void) */ /* - * unknown record (route params?) lives here + * outercount is the number of route segments (start+end+stops+vias-1) */ - count = ReadLong(infile); - while (count) { + + outercount = ReadLong(infile); + while (outercount) { + + /* + * unknown record (route params?) lives here + */ ReadShort(infile); recsize = ReadLong(infile); Skip(infile, recsize); - count--; - } - /* - * end of unknown record - */ - /* - * routing begins here - */ - count = ReadLong(infile); - if ( count ) { - track_head = route_head_alloc(); - route_add_head(track_head); - } - while (count) { - ReadShort(infile); - recsize = ReadLong(infile); - record = ReadRecord(infile, recsize); - stringlen = le_read16((unsigned short *)record); - coordcount = - le_read16((unsigned short *)(record + 2 + stringlen + 0x3c)); - latlon = (struct ll *)(record + 2 + stringlen + 0x3c + 2); - count--; - if (count) { - coordcount--; + /* + * end of unknown record + */ + + /* + * routing begins here + */ + count = ReadLong(infile); + if ( count ) { + track_head = route_head_alloc(); + route_add_head(track_head); } - while (coordcount) { - double lat; - double lon; - - wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1); - - lat = (0x80000000UL - - le_read32(&latlon->lat)) / (double)(0x800000); - lon = (0x80000000UL - - le_read32(&latlon->lon)) / (double)(0x800000); - - wpt_tmp->latitude = lat; - wpt_tmp->longitude = -lon; - wpt_tmp->shortname = xmalloc(7); - sprintf( wpt_tmp->shortname, "\\%5.5x", serial++ ); - route_add_wpt(track_head, wpt_tmp); - - latlon++; - coordcount--; + while (count) { + ReadShort(infile); + recsize = ReadLong(infile); + record = ReadRecord(infile, recsize); + stringlen = le_read16((unsigned short *)record); + coordcount = le_read16((unsigned short *) + (record + 2 + stringlen + 0x3c)); + latlon = (struct ll *)(record + 2 + stringlen + 0x3c + 2); + count--; + if (count) { + coordcount--; + } + while (coordcount) { + double lat; + double lon; + + wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1); + + lat = (0x80000000UL - + le_read32(&latlon->lat)) / + (double)(0x800000); + lon = (0x80000000UL - + le_read32(&latlon->lon)) / + (double)(0x800000); + + wpt_tmp->latitude = lat; + wpt_tmp->longitude = -lon; + wpt_tmp->shortname = xmalloc(7); + sprintf( wpt_tmp->shortname, "\\%5.5x", + serial++ ); + route_add_wpt(track_head, wpt_tmp); + + latlon++; + coordcount--; + } + xfree(record); } - xfree(record); + /* + * end of routing + */ + outercount--; } - /* - * end of routing - */ } -- 2.30.2